#############################################################################################
#                                                                                           #
#                   Copyright 2010-2013 Ning, Inc.                                          #
#                   Copyright 2014 Groupon, Inc.                                            #
#                   Copyright 2014 The Billing Project, LLC                                 #
#                                                                                           #
#      The Billing Project licenses this file to you under the Apache License, version 2.0  #
#      (the "License"); you may not use this file except in compliance with the             #
#      License.  You may obtain a copy of the License at:                                   #
#                                                                                           #
#          http://www.apache.org/licenses/LICENSE-2.0                                       #
#                                                                                           #
#      Unless required by applicable law or agreed to in writing, software                  #
#      distributed under the License is distributed on an "AS IS" BASIS, WITHOUT            #
#      WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the            #
#      License for the specific language governing permissions and limitations              #
#      under the License.                                                                   #
#                                                                                           #
#############################################################################################


#
#                       DO NOT EDIT!!!
#    File automatically generated by killbill-java-parser (git@github.com:killbill/killbill-java-parser.git)
#


require 'killbill/gen/plugin-api/notification_plugin_api'
module Killbill
  module Plugin
    module Api

      java_package 'org.killbill.billing.payment.plugin.api'
      class PaymentPluginApi < NotificationPluginApi

        include org.killbill.billing.payment.plugin.api.PaymentPluginApi

        def initialize(real_class_name, services = {})
          super(real_class_name, services)
        end


        java_signature 'Java::org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin authorizePayment(Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.math.BigDecimal, Java::org.killbill.billing.catalog.api.Currency, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def authorize_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentId [type = java.util.UUID]
          kbPaymentId = kbPaymentId.nil? ? nil : kbPaymentId.to_s

          # conversion for kbTransactionId [type = java.util.UUID]
          kbTransactionId = kbTransactionId.nil? ? nil : kbTransactionId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for amount [type = java.math.BigDecimal]
          amount = amount.nil? ? 0 : BigDecimal.new(amount.to_s)

          # conversion for currency [type = org.killbill.billing.catalog.api.Currency]
          currency = currency.to_s.to_sym unless currency.nil?

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.authorize_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)
            # conversion for res [type = org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in authorize_payment: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("authorize_payment failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin capturePayment(Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.math.BigDecimal, Java::org.killbill.billing.catalog.api.Currency, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def capture_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentId [type = java.util.UUID]
          kbPaymentId = kbPaymentId.nil? ? nil : kbPaymentId.to_s

          # conversion for kbTransactionId [type = java.util.UUID]
          kbTransactionId = kbTransactionId.nil? ? nil : kbTransactionId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for amount [type = java.math.BigDecimal]
          amount = amount.nil? ? 0 : BigDecimal.new(amount.to_s)

          # conversion for currency [type = org.killbill.billing.catalog.api.Currency]
          currency = currency.to_s.to_sym unless currency.nil?

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.capture_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)
            # conversion for res [type = org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in capture_payment: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("capture_payment failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin purchasePayment(Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.math.BigDecimal, Java::org.killbill.billing.catalog.api.Currency, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def purchase_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentId [type = java.util.UUID]
          kbPaymentId = kbPaymentId.nil? ? nil : kbPaymentId.to_s

          # conversion for kbTransactionId [type = java.util.UUID]
          kbTransactionId = kbTransactionId.nil? ? nil : kbTransactionId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for amount [type = java.math.BigDecimal]
          amount = amount.nil? ? 0 : BigDecimal.new(amount.to_s)

          # conversion for currency [type = org.killbill.billing.catalog.api.Currency]
          currency = currency.to_s.to_sym unless currency.nil?

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.purchase_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)
            # conversion for res [type = org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in purchase_payment: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("purchase_payment failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin voidPayment(Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def void_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentId [type = java.util.UUID]
          kbPaymentId = kbPaymentId.nil? ? nil : kbPaymentId.to_s

          # conversion for kbTransactionId [type = java.util.UUID]
          kbTransactionId = kbTransactionId.nil? ? nil : kbTransactionId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.void_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, properties, context)
            # conversion for res [type = org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in void_payment: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("void_payment failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin creditPayment(Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.math.BigDecimal, Java::org.killbill.billing.catalog.api.Currency, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def credit_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentId [type = java.util.UUID]
          kbPaymentId = kbPaymentId.nil? ? nil : kbPaymentId.to_s

          # conversion for kbTransactionId [type = java.util.UUID]
          kbTransactionId = kbTransactionId.nil? ? nil : kbTransactionId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for amount [type = java.math.BigDecimal]
          amount = amount.nil? ? 0 : BigDecimal.new(amount.to_s)

          # conversion for currency [type = org.killbill.billing.catalog.api.Currency]
          currency = currency.to_s.to_sym unless currency.nil?

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.credit_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)
            # conversion for res [type = org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in credit_payment: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("credit_payment failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin refundPayment(Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.util.UUID, Java::java.math.BigDecimal, Java::org.killbill.billing.catalog.api.Currency, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def refund_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentId [type = java.util.UUID]
          kbPaymentId = kbPaymentId.nil? ? nil : kbPaymentId.to_s

          # conversion for kbTransactionId [type = java.util.UUID]
          kbTransactionId = kbTransactionId.nil? ? nil : kbTransactionId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for amount [type = java.math.BigDecimal]
          amount = amount.nil? ? 0 : BigDecimal.new(amount.to_s)

          # conversion for currency [type = org.killbill.billing.catalog.api.Currency]
          currency = currency.to_s.to_sym unless currency.nil?

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.refund_payment(kbAccountId, kbPaymentId, kbTransactionId, kbPaymentMethodId, amount, currency, properties, context)
            # conversion for res [type = org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in refund_payment: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("refund_payment failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::java.util.List getPaymentInfo(Java::java.util.UUID, Java::java.util.UUID, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.TenantContext)'
        def get_payment_info(kbAccountId, kbPaymentId, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentId [type = java.util.UUID]
          kbPaymentId = kbPaymentId.nil? ? nil : kbPaymentId.to_s

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.TenantContext]
          context = Killbill::Plugin::Model::TenantContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.get_payment_info(kbAccountId, kbPaymentId, properties, context)
            # conversion for res [type = java.util.List]
            tmp = java.util.ArrayList.new
            (res || []).each do |m|
              # conversion for m [type = org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin]
              m = m.to_java unless m.nil?
              tmp.add(m)
            end
            res = tmp
            return res
          rescue Exception => e
            message = "Failure in get_payment_info: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("get_payment_info failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.util.entity.Pagination searchPayments(Java::java.lang.String, Java::java.lang.Long, Java::java.lang.Long, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.TenantContext)'
        def search_payments(searchKey, offset, limit, properties, context)

          # conversion for searchKey [type = java.lang.String]

          # conversion for offset [type = java.lang.Long]

          # conversion for limit [type = java.lang.Long]

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.TenantContext]
          context = Killbill::Plugin::Model::TenantContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.search_payments(searchKey, offset, limit, properties, context)
            # conversion for res [type = org.killbill.billing.util.entity.Pagination]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in search_payments: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("search_payments failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::void addPaymentMethod(Java::java.util.UUID, Java::java.util.UUID, Java::org.killbill.billing.payment.api.PaymentMethodPlugin, Java::boolean, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def add_payment_method(kbAccountId, kbPaymentMethodId, paymentMethodProps, setDefault, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for paymentMethodProps [type = org.killbill.billing.payment.api.PaymentMethodPlugin]
          paymentMethodProps = Killbill::Plugin::Model::PaymentMethodPlugin.new.to_ruby(paymentMethodProps) unless paymentMethodProps.nil?

          # conversion for setDefault [type = boolean]
          if setDefault.nil?
            setDefault = false
          else
            tmp_bool = (setDefault.java_kind_of? java.lang.Boolean) ? setDefault.boolean_value : setDefault
            setDefault = tmp_bool ? true : false
          end

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            @delegate_plugin.add_payment_method(kbAccountId, kbPaymentMethodId, paymentMethodProps, setDefault, properties, context)
          rescue Exception => e
            message = "Failure in add_payment_method: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("add_payment_method failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::void deletePaymentMethod(Java::java.util.UUID, Java::java.util.UUID, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def delete_payment_method(kbAccountId, kbPaymentMethodId, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            @delegate_plugin.delete_payment_method(kbAccountId, kbPaymentMethodId, properties, context)
          rescue Exception => e
            message = "Failure in delete_payment_method: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("delete_payment_method failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.payment.api.PaymentMethodPlugin getPaymentMethodDetail(Java::java.util.UUID, Java::java.util.UUID, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.TenantContext)'
        def get_payment_method_detail(kbAccountId, kbPaymentMethodId, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.TenantContext]
          context = Killbill::Plugin::Model::TenantContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.get_payment_method_detail(kbAccountId, kbPaymentMethodId, properties, context)
            # conversion for res [type = org.killbill.billing.payment.api.PaymentMethodPlugin]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in get_payment_method_detail: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("get_payment_method_detail failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::void setDefaultPaymentMethod(Java::java.util.UUID, Java::java.util.UUID, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def set_default_payment_method(kbAccountId, kbPaymentMethodId, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for kbPaymentMethodId [type = java.util.UUID]
          kbPaymentMethodId = kbPaymentMethodId.nil? ? nil : kbPaymentMethodId.to_s

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            @delegate_plugin.set_default_payment_method(kbAccountId, kbPaymentMethodId, properties, context)
          rescue Exception => e
            message = "Failure in set_default_payment_method: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("set_default_payment_method failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::java.util.List getPaymentMethods(Java::java.util.UUID, Java::boolean, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def get_payment_methods(kbAccountId, refreshFromGateway, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for refreshFromGateway [type = boolean]
          if refreshFromGateway.nil?
            refreshFromGateway = false
          else
            tmp_bool = (refreshFromGateway.java_kind_of? java.lang.Boolean) ? refreshFromGateway.boolean_value : refreshFromGateway
            refreshFromGateway = tmp_bool ? true : false
          end

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.get_payment_methods(kbAccountId, refreshFromGateway, properties, context)
            # conversion for res [type = java.util.List]
            tmp = java.util.ArrayList.new
            (res || []).each do |m|
              # conversion for m [type = org.killbill.billing.payment.plugin.api.PaymentMethodInfoPlugin]
              m = m.to_java unless m.nil?
              tmp.add(m)
            end
            res = tmp
            return res
          rescue Exception => e
            message = "Failure in get_payment_methods: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("get_payment_methods failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.util.entity.Pagination searchPaymentMethods(Java::java.lang.String, Java::java.lang.Long, Java::java.lang.Long, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.TenantContext)'
        def search_payment_methods(searchKey, offset, limit, properties, context)

          # conversion for searchKey [type = java.lang.String]

          # conversion for offset [type = java.lang.Long]

          # conversion for limit [type = java.lang.Long]

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.TenantContext]
          context = Killbill::Plugin::Model::TenantContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.search_payment_methods(searchKey, offset, limit, properties, context)
            # conversion for res [type = org.killbill.billing.util.entity.Pagination]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in search_payment_methods: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("search_payment_methods failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::void resetPaymentMethods(Java::java.util.UUID, Java::java.util.List, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def reset_payment_methods(kbAccountId, paymentMethods, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for paymentMethods [type = java.util.List]
          tmp = []
          (paymentMethods || []).each do |m|
            # conversion for m [type = org.killbill.billing.payment.plugin.api.PaymentMethodInfoPlugin]
            m = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          paymentMethods = tmp

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            @delegate_plugin.reset_payment_methods(kbAccountId, paymentMethods, properties, context)
          rescue Exception => e
            message = "Failure in reset_payment_methods: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("reset_payment_methods failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor buildFormDescriptor(Java::java.util.UUID, Java::java.lang.Iterable, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def build_form_descriptor(kbAccountId, customFields, properties, context)

          # conversion for kbAccountId [type = java.util.UUID]
          kbAccountId = kbAccountId.nil? ? nil : kbAccountId.to_s

          # conversion for customFields [type = java.lang.Iterable]
          tmp = []
          (customFields.nil? ? [] : customFields.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          customFields = tmp

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.build_form_descriptor(kbAccountId, customFields, properties, context)
            # conversion for res [type = org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in build_form_descriptor: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("build_form_descriptor failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end

        java_signature 'Java::org.killbill.billing.payment.plugin.api.GatewayNotification processNotification(Java::java.lang.String, Java::java.lang.Iterable, Java::org.killbill.billing.util.callcontext.CallContext)'
        def process_notification(notification, properties, context)

          # conversion for notification [type = java.lang.String]

          # conversion for properties [type = java.lang.Iterable]
          tmp = []
          (properties.nil? ? [] : properties.iterator).each do |m|
            # conversion for m [type = org.killbill.billing.payment.api.PluginProperty]
            m = Killbill::Plugin::Model::PluginProperty.new.to_ruby(m) unless m.nil?
            tmp << m
          end
          properties = tmp

          # conversion for context [type = org.killbill.billing.util.callcontext.CallContext]
          context = Killbill::Plugin::Model::CallContext.new.to_ruby(context) unless context.nil?
          begin
            res = @delegate_plugin.process_notification(notification, properties, context)
            # conversion for res [type = org.killbill.billing.payment.plugin.api.GatewayNotification]
            res = res.to_java unless res.nil?
            return res
          rescue Exception => e
            message = "Failure in process_notification: #{e}"
            unless e.backtrace.nil?
              message = "#{message}\n#{e.backtrace.join("\n")}"
            end
            logger.warn message
            raise Java::org.killbill.billing.payment.plugin.api.PaymentPluginApiException.new("process_notification failure", e.message)
          ensure
            @delegate_plugin.after_request
          end
        end
      end
    end
  end
end
